﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KerriganDataContract;
using System.Web.Security;
using KerriganForum;
using KerriganDataContract.Person;

namespace KerriganDataContract
{
    public class Identify
    {
        private static bool? _anonymous;
        private static int _idUser;
        private static string _nickName;
        private static int _typeUser;

        public static int IdUser
        {
            get
            {
                return _idUser;
            }
            set
            {
                _idUser = value;
            }
        }

        public static string NickName
        {
            get
            {
                return _nickName;
            }
            set
            {
                _nickName = value;
            }
        }

        public static int TypeUser
        {
            get
            {
                return _typeUser;
            }
            set
            {
                _typeUser = value;
            }
        }

        public static bool? Anonymous { 
            
            get{

                return _anonymous;
            }


            set {

                _anonymous = value;
            }
        }

        public static void CheckUser(String requestCookie)
        {

            using (ServiceProxy Srv = new ServiceProxy())
            {


                if (requestCookie != null)
                {
                    FormsAuthenticationTicket authentification = FormsAuthentication.Decrypt(requestCookie);
                    string user = authentification.UserData;
                    string[] infosUser = user.Split(',');
                    NickName = infosUser[0];
                    IdUser = int.Parse(infosUser[2]);
                    TypeUser =int.Parse(infosUser[3]);

                    Anonymous = false;
                }
                else {
                    NickName = "";
                    IdUser = 0;
                    TypeUser = 0;
                    Anonymous = true;
                
                }



            }


        }

    }
}
